<?php

    #-------------------------------------------------------------#
	# This file is part of the Tekuna MVC Microframework for PHP. #
	# (c) 2009 Niels Jäckel <niels.jaeckel@tekuna.org>            #
	# Please visit http://tekuna.org/ for more information.       #
	#                                                             #
	# This software is licensed under the MIT License. Please     #
	# view the LICENSE file for the full text of this license.    #
    #-------------------------------------------------------------#


	Tekuna :: load('org.tekuna.test.testApplication.components.controller.TestController');


	class ControllerTest extends AbstractTekunaTestCase {

		public function testAbstractController() {

			// create testing controller instance
			$objContext = new TekunaApplicationContext();
			$objContext -> setRequest(new Request());
			$objContext -> setResponse(new Response());
			$objContext -> setURLInformation(new URLInformation());
			$objContext -> setClientInformation(new ClientInformation());
			$objContext -> setApplicationLanguage('en-us');

			// instantiate new controller with fresh context
			$objController = new TestController($objContext);

			// test getters
			$this -> assertIdentical($objController -> getApplicationContext(), $objContext);

			// test the "mock" output
			$this -> assertIdentical($objController -> getOutput(), 'testOutput');
		}
		
		
		public function testURLParts() {

			// prepare context with URL information			
			$objContext = new TekunaApplicationContext();
			$objURLInformation = new URLInformation();
			$objContext -> setURLInformation($objURLInformation);
			
			// test exception at wrong URL parts count
			try {

				// 0 URL parts - wrong			
				$objController = new TestController2($objContext);
				$this -> fail();	
			}
			catch (ControllerURLException $e) {
				
				$this -> pass();
			}
			
			// test exception at wrong URL parts count
			try {

				// 1 URL part - wrong
				$objURLInformation -> setMatchedURLParts(array('foo'));			
				$objController = new TestController2($objContext);
				$this -> fail();	
			}
			catch (ControllerURLException $e) {
				
				$this -> pass();
			}

			// test exception at correct URL parts count
			try {

				// 2 URL parts - correct
				$objURLInformation -> setMatchedURLParts(array('foo', 'bar'));			
				$objController = new TestController2($objContext);
				$this -> pass();	
			}
			catch (ControllerURLException $e) {
				
				$this -> fail();
			}

			// test exception at wrong URL parts count
			try {

				// 3 URL parts - wrong
				$objURLInformation -> setMatchedURLParts(array('foo', 'bar', 'baz'));			
				$objController = new TestController2($objContext);
				$this -> fail();	
			}
			catch (ControllerURLException $e) {
				
				$this -> pass();
			}

			
			// test URL parts array conversion
			$objURLInformation -> setMatchedURLParts(array('foo', 'bar'));			
			$objController = new TestController2($objContext);
			$this -> assertIdentical($objURLInformation -> getMatchedURLParts(), array('part1' => 'foo', 'part2' => 'bar'));
		}
	}



